package ngames.com.sushitv.action;

import android.app.Activity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Toast;

import com.google.gson.annotations.SerializedName;

import java.util.ArrayList;

import ngames.com.sushitv.AppApplication;
import ngames.com.sushitv.R;
import ngames.com.sushitv.adapter.DemoAdapter;
import ngames.com.sushitv.adapter.SearchPromptAdapter;
import ngames.com.sushitv.base.BaseListAction;
import ngames.com.sushitv.core.ModelCallback;
import ngames.com.sushitv.entity.ItemVideo;
import ngames.com.sushitv.entity.PromptUser;
import ngames.com.sushitv.entity.SearchPrompt;
import ngames.com.sushitv.interfaces.OnItemClickListener;
import ngames.com.sushitv.tools.Constants;

/**
 * Created by Jeffrey on 2016/7/27.
 */
public class SearchPromptAction extends BaseListAction {
    private String videoDataID = "0", userDataID = "0";
    private RecyclerView videoRecycler, userRecycler;
    private SearchPromptAdapter mAdapterVideo, mAdapterUser;
    public SearchPromptAction(Activity activity, View baseView) {
        super(activity, baseView);
    }
    private SearchPromptAction searchPromptAction;
    @Override
    public void onCreate() {
        super.onCreate();
        //onRefreshData();
        searchPromptAction=this;
        videoRecycler= (RecyclerView) mBaseView.findViewById(R.id.recycler_search_videos);
        userRecycler= (RecyclerView) mBaseView.findViewById(R.id.recycler_search_users);
        videoRecycler.setHasFixedSize(true);
        //mRecycler.setLayoutManager(mLinearLayoutManager);
        videoRecycler.setLayoutManager(new GridLayoutManager(mActivity, 1));
        userRecycler.setHasFixedSize(true);
        //mRecycler.setLayoutManager(mLinearLayoutManager);
        userRecycler.setLayoutManager(new GridLayoutManager(mActivity, 1));
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onRefreshData() {
       /* videoDataID = "0";
        userDataID = "0";*/
        //SearchPrompt();
        SearchPrompt(AppApplication.getSearchPrompt());
    }

    @Override
    public void loadMore() {
//        videoRank();
    }

    private void SearchPrompt(SearchPrompt searchPrompt) {

        mIsLoadingMore = false;
       // mSwipeRefreshLayout.setRefreshing(false);
        ArrayList<String> videoData=new ArrayList<>();
        if(searchPrompt.getTitle()!=null) {
            videoData.addAll(searchPrompt.getTitle());
        }
        if (mAdapterVideo != null) {
            mAdapterVideo.clearData();
        }
        if (isEmptyList(videoData)) {
            videoData.add("未找到结果");
        }
        //videoDataID ="2"; //videoData.get(videoData.size() - 1).getId();
        setListData(videoData);

       // mIsLoadingMore = false;
        // mSwipeRefreshLayout.setRefreshing(false);
        ArrayList<PromptUser> userData=new ArrayList<>();
        if(searchPrompt.getUser()!=null) {
            userData.addAll(searchPrompt.getUser());
        }
        if (mAdapterUser != null) {
            mAdapterUser.clearData();
        }
        if (isEmptyList(userData)) {
            //userData.add("未找到结果");
        }
        //videoDataID ="2"; //videoData.get(videoData.size() - 1).getId();
        setUserListData(userData);
    }

    private void setListData(ArrayList<String> data) {
        if (mAdapterVideo == null) {
            mAdapterVideo = new SearchPromptAdapter(mActivity,data,null,1,searchPromptAction);
            videoRecycler.setAdapter(mAdapterVideo);
        }
    }

    public void setUserListData(ArrayList<PromptUser> data) {
        if (mAdapterUser == null) {
            mAdapterUser = new SearchPromptAdapter(mActivity,null, data,2,searchPromptAction);

            userRecycler.setAdapter(mAdapterUser);
        }
    }
    public void searchResultData(String finalKey, int flag){
        //AppApplication.setSearchKeyWord(finalKey);

    }
}
